import Taro, { Component } from '@tarojs/taro';
import { View, Image } from '@tarojs/components';
import { DNavBar, DCheckOpinion, DLookImages } from '@/components';
import './index.scss';
import http from '@/api'

export default class CompanyCheckDetail extends Component {
  state = {
    moneyIcon: require('@/assets/images/money_icon.png'),
    fileIcon: require('@/assets/images/file_icon.png'),
    opinions: [{
      name: '审核通过',
      value: 'success'
    }, {
      name: '审核不通过',
      value: 'fail'
    }],

    detail: {},
    previewImg: {
      itemStatus: false,
      itemUrl: ''
    },
  }
  componentDidMount() {
    this.getEntAuthDetail()
  }
  handleCancel(){
  	  Taro.navigateTo({
  		  url:'/pages/companyCheck'
  	  })
  }
  handleConfirm(state){
	  let {detail} = this.state
	  http.enterpriseReview({
		  creatorId:detail.creatorId,
		  id:detail.id,
		  isAppro:state.checkOpinion=='fail'?0:1,
		  approDesc:state.explain
	  }).then(data=>{
      Taro.showToast({
        title: '操作成功',
        duration: 2000
      })
		  setTimeout(Taro.navigateBack, 2000);
	  })

  }
  getEntAuthDetail() {
    const { id } = this.$router.params
    http.getEntAuthDetail({ id }).then((detail) => {
      this.handleDetailData(detail)
      this.setState({ detail })
    })
  }
  handleDetailData(detail) {
    const infoMap = {

    }
  }
  // 图片预览
  onLookHandle(url) {
    if (window.bridge) {
      let _images = [], i = 0
      _images.push(url)
      window.bridge.callHandler('previewPhoto', { "index": i, "images": _images }, function responseCallback() { })
    } else {
      this.setState({
        previewImg: {
          itemStatus: true,
          itemUrl: url
        }
      })
    }
  }
  onLookItem() {
    this.setState({
      previewImg: {
        ...this.state.previewImg,
        itemStatus: false,
        itemUrl: ''
      }
    })
  }

  render() {
    const { opinions,detail, previewImg } = this.state;

    return (
      <View className="mortgage-check-detail">
        <DNavBar title="企业入驻审核详情"></DNavBar>

        <View className="info">
          <View className="item">
            <View className="label">公司名称</View>
            <View className="value">{detail.entName}</View>
          </View>
          <View className="item">
            <View className="label">社会信用代码</View>
            <View className="value">{detail.entCreditCode}</View>
          </View>
          <View className="item">
            <View className="label">法人姓名</View>
            <View className="value">{detail.entOwner}</View>
          </View>
          <View className="item">
            <View className="label">所在区域</View>
            <View className="value">{detail.entDis}</View>
          </View>
          <View className="item">
            <View className="label">企业地址</View>
            <View className="value">{detail.entAddr}</View>
          </View>
          <View className="item">
            <View className="label">所在性质</View>
            <View className="value">{detail.entAtt}</View>
          </View>
          <View className="item">
            <View className="label">企业营业执照</View>
            <View className="value">
              <Image className="photo" src={detail.entLicenseUrl} onClick={this.onLookHandle.bind(this, detail.entLicenseUrl)}></Image>
            </View>
          </View>
          <View className="item">
            <View className="label">法人身份证</View>
            <View className="value">
              { detail.fileList && detail.fileList.map(list => [2,3].indexOf(Number(list.cfType)) >-1 &&
                  <Image className="photo" src={list.cfFileUrl} onClick={this.onLookHandle.bind(this, list.cfFileUrl)}></Image>)
              }
            </View>
          </View>
          <View className="item">
            <View className="label">企业门店照</View>
            <View className="value">
              { detail.fileList && detail.fileList.map(list => list.cfType == 4 &&
                <Image className="photo" src={list.cfFileUrl} onClick={this.onLookHandle.bind(this, list.cfFileUrl)}></Image>) }
            </View>
          </View>
        </View>

        {
          (detail.eaIsAppro == 1 || detail.eaIsAppro == 2) && <View className="check-detail">
            <View className="check-detail__title">审核</View>
            <View className="item">
              <View className="label">审核操作</View>
              <View className="value">{ { 1: '审核通过', 2: '审核未通过' }[detail.eaIsAppro] }</View>
            </View>
            <View className="item">
              <View className="label">审核意见</View>
              <View className="value">{ detail.approDesc || '---' }</View>
            </View>
            <View className="item">
              <View className="label">审核时间</View>
              <View className="value">{ detail.approTime || '---' }</View>
            </View>
          </View>
        }

        {
          (detail.eaIsAppro === '3' || detail.eaIsAppro === '0') && <View>
            <View className="border"></View>
            <DCheckOpinion opinions={opinions} onCancel={this.handleCancel.bind(this)}   onConfirm={this.handleConfirm.bind(this)} checkOpinion={+detail.authStatus==2?'success':'fail'} explain={detail.authDesc}/>
          </View>
        }

        <DLookImages status={previewImg.itemStatus} url={previewImg.itemUrl} onLookHandle={this.onLookItem.bind(this)}></DLookImages>
      </View>
    )
  }
}
